package com.zhika.zishi.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableRow;

import com.zhika.zishi.R;
import com.zhika.zishi.interfaces.ChannelPopInterface;

/**
 * Created by shi-02 on 2015/4/13.
 */
public class OptionsPopView extends RelativeLayout {


    private Context context;

    private ImageView imageView;

    private TableRow optionsRow;

    private Button heatButton;

    private Button timeButton;

    private ChannelPopInterface popInterface;

    public void setPopInterface(ChannelPopInterface popInterface){
        this.popInterface = popInterface;
    }

    public OptionsPopView(Context context) {
        this(context, null);
    }

    public OptionsPopView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public OptionsPopView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        this.context = context;

        initView();
    }

    private void initView(){
        View view = LayoutInflater.from(context).inflate(R.layout.channel_pop_layout,this);

        optionsRow = (TableRow) view.findViewById(R.id.channel_pop_options_row);
        imageView = (ImageView) view.findViewById(R.id.channel_pop_image_view);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                optionsRow.setVisibility(VISIBLE);
            }
        });

        heatButton = (Button) view.findViewById(R.id.channel_item_heat_button);
        heatButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                heatButton.setBackgroundColor(getResources().getColor(R.color.color_white));
                heatButton.setTextColor(getResources().getColor(R.color.color_black));

                timeButton.setBackgroundColor(getResources().getColor(R.color.color_black));
                timeButton.setTextColor(getResources().getColor(R.color.color_white));

                optionsRow.setVisibility(GONE);
                popInterface.heatListener();
            }
        });
        timeButton = (Button) view.findViewById(R.id.channel_item_time_button);
        timeButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                timeButton.setBackgroundColor(getResources().getColor(R.color.color_white));
                timeButton.setTextColor(getResources().getColor(R.color.color_black));

                heatButton.setBackgroundColor(getResources().getColor(R.color.color_black));
                heatButton.setTextColor(getResources().getColor(R.color.color_white));
                optionsRow.setVisibility(GONE);
                popInterface.timeListener();
            }
        });
    }

    public void hideOptions(){
        optionsRow.setVisibility(GONE);
    }

}
